﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using IHISCETeim.DAL;
using IHISCETeim.Model;
using IHISCETeim.Library;
using System.Data;


namespace IHISCETeim.BLL
{
    /// <summary>
    /// 3.应收账款帐龄明细表(FTradeAgeDetail)
    /// </summary>
    public class FTradeAgeDetailController : BaseController
    {
        /// <summary>
        /// 添加帐龄明细记录,注意,一般不直接使用
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static int Add(FTradeAgeDetailInfo obj)
        {
            return FTradeAgeDetailDAL.Add(obj);
        }
        public static int Adds(List<FTradeAgeDetailInfo> objs)
        {
            return FTradeAgeDetailDAL.Adds(objs);
        }
        /// <summary>
        /// 根据销售类型历史ID来获取对应的所有的帐龄明细
        /// </summary>
        /// <param name="FTradeSalesId"></param>
        /// <returns></returns>
        public static List<FTradeAgeDetailInfo> GetAllByFTradeSalesId(int FTradeSalesId)
        {
            return  CBO.FillCollection<FTradeAgeDetailInfo>(FTradeAgeDetailDAL.GetAllByFTradeSalesId(FTradeSalesId));
        }
        /// <summary>
        /// 根据ID　获取应收账款帐龄明细
        /// </summary>
        /// <param name="FTradeAgeId"></param>
        /// <returns></returns>
        public static FTradeAgeDetailInfo GetByFTradeAgeId(int FTradeAgeId)
        {
            return CBO.FillObject<FTradeAgeDetailInfo>(FTradeAgeDetailDAL.GetByFTradeAgeId(FTradeAgeId));
        }

        /// <summary>
        /// 获取可冲帐的记录
        /// </summary>
        /// <param name="WhereSql"></param>
        /// <returns></returns>
        public static DataTable GetBalancePagination(string WhereSql, int PageIndex, int PageSize, string Sort, ref int TotalCount)
        {
            return FTradeAgeDetailDAL.GetBalancePagination(WhereSql, PageIndex, PageSize, Sort, ref  TotalCount);
        }
        /// <summary>
        /// 根据ID　获取最后一条帐龄信息
        /// </summary>
        /// <param name="FTradeID"></param>
        /// <returns></returns>
        public static FTradeAgeDetailInfo GetLastByFTradeID(int FTradeID)
        {
            return CBO.FillObject<FTradeAgeDetailInfo>(FTradeAgeDetailDAL.GetLastByFTradeID(FTradeID));
        }

        public static string GetFKState(int FTradeAgeId)
        {
            string fkstate= FTradeAgeDetailDAL.GetFKState(FTradeAgeId);
            string fkstr = "<span style=\"color:{1};\">{0}</span>";
            switch (fkstate)
            { 
                case "逾期-未付清":
                    fkstr = string.Format(fkstr, fkstate, "#FF6666");
                    break;
                case "逾期-付清":
                    fkstr = string.Format(fkstr, fkstate, "#FFCC99");
                    break;
                case "逾期-未付":
                    fkstr = string.Format(fkstr, fkstate, "red");
                    break;
                default:
                    fkstr = fkstate;
                    break;

            }

            return fkstr;
        }
    }
}
